import load

def add(s,con):
    if type(con)==type('a'):
        return s+','+con
    else:
        return s+','+repr(con)

def addSubject(s,num):
    subScore = load.getCell(i, num)
    classRank = load.getCell(i, num+1)
    schoolRank = load.getCell(i, num+2)
    s = add(s, subScore)
    s = add(s, classRank)
    s = add(s, schoolRank)

    if subScore=='':
        return s, 0
    else:
        return s, float(subScore)

allContent=''

for i in range(1,17):
    load.setTable(repr(i)+'班')
    for i in range(2,80):
        try:
            str=load.getCell(i,load.Number)
        except IndexError:
            break
        str = add(str, load.getCell(i, load.Name))
        str = add(str, load.getCell(i, load.Class))
        str = add(str, load.getCell(i, load.totScore))
        str = add(str, load.getCell(i, load.classRank))
        str = add(str, load.getCell(i, load.schoolRank))
        str, chineseScore = addSubject(str, load.Chinese)
        str, mathScore = addSubject(str, load.Math)
        str, englishScore = addSubject(str, load.English)
        str, physicsScore = addSubject(str, load.Physics)
        str, chemScore = addSubject(str, load.Chem)
        str, bioloScore = addSubject(str, load.Biolo)
        scienceScore = chineseScore+mathScore+englishScore+physicsScore+chemScore+bioloScore
        str = add(str, scienceScore)
        allContent += str+'\n'

print(allContent)
load.writeFile('理科汇总表.csv',allContent)

